<template>
	<view :data-theme="theme">
		<view class='integral-details'>
			<view class='header'>
				<view class="integral-sum1">{{integral.sumIntegral}}</view>
				<view class="integral-sum2">累计获得</view>
				<view class="integral-num">
					<view class="integral-num-item">
						<view class="integral-num-item-text1">{{integral.waitIntegral}}</view>
						<view class="integral-num-item-text2">待到账</view>
					</view>
					<view class="integral-num-item">
						<view class="integral-num-item-text1">{{integral.deductionIntegral}}</view>
						<view class="integral-num-item-text2">已使用</view>
					</view>
					<view class="integral-num-item">
						<view class="integral-num-item-text1">{{integral.integral}}</view>
						<view class="integral-num-item-text2">可使用</view>
					</view>
				</view>
			</view>
			<view class='wrapper'>
				<view class='nav acea-row' style="display: flex;align-items: center;justify-content: center;">
					<view class='item acea-row row-center-wrapper'><text class='iconfont2 icon2-ks2_price3' style="font-size: 40rpx;"></text>积分兑换</view>
					<view style="width: 1rpx;height: 40rpx;background: #DDDDE9;"></view>
					<view class='item acea-row row-center-wrapper'><text class='iconfont2 icon2-24px'></text>积分竞猜</view>
				</view>
				<view class="tab">
					<view class="tab-itme" @click="nav('2')" :class="current==2?'tab-itme-on':''">累计获得</view>
					<view class="tab-itme" @click="nav('1')" :class="current==1?'tab-itme-on':''">待到账</view>
					<view class="tab-itme" @click="nav('3')" :class="current==3?'tab-itme-on':''">已使用</view>
					<view class="tab-itme" @click="nav('4')" :class="current==4?'tab-itme-on':''">已取消</view>
				</view>
				<view class='list'>
					<view class="item1" v-for="(item, key) in integralList" :index='key'>
						<view class="item1-body">
							<view style="position: relative;">
								<image class="item1-image" :src="item.image"></image>
								<view class="status1" v-if="current==2">已到账</view>
								<view class="status3" v-if="current==1">待到账</view>
								<view class="status1" v-if="current==3">已使用</view>
								<view class="status2" v-if="current==4">已取消</view>
							</view>
							<view style="flex: 1">
								<view class="item1-price">
									<text class="item1-price-name" v-if="item.reasonType==501 || item.reasonType==505">{{item.reasonTitle}}</text>
									<text class="item1-price-name" v-else>{{item.productName}}</text>
									<text class="item1-price-num">¥{{item.integral}}</text>
								</view>
								<view class="item1-page">
									<view class="item1-text1">订单数量：</view>
									<view class="item1-text2">{{item.payNum || 1}}</view>
								</view>
								<view class="item1-page">
									<view class="item1-text1" >订单编号：</view>
									<view class="item1-text2">{{item.linkId}}</view>
								</view>
								<view class="item1-page">
									<view class="item1-text1" v-if="item.status==4">订单取消：</view>
									<view class="item1-text1" v-else>下单时间：</view>
									<view class="item1-text2">{{item.createTime}}</view>
								</view>
						</view>
						
						</view>
						
					</view>
					<view class='loadingicon acea-row row-center-wrapper' v-if="integralList.length>0">
						<text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
					</view>
					<view v-if="integralList.length == 0">
						<emptyPage title="暂无积分记录哦～"></emptyPage>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { postIntegralUser, getIntegralList } from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import emptyPage from '@/components/emptyPage.vue'
	let app = getApp();
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				urlDomain: this.$Cache.get("imgHost"),
				navList: [{
						'name': '积分兑换',
						'icon': 'icon-mingxi'
					},
					{
						'name': '积分竞猜',
						'icon': 'icon-tishengfenzhi'
					}
				],
				current: 2,
				page: 1,
				limit: 10,
				integralList: [],
				integral:{},
				loadend: false,
				loading: false,
				loadTitle: '加载更多',
				theme:app.globalData.theme,
			};
		},
		computed: mapGetters(['isLogin']),
		watch:{
			isLogin:{
				handler:function(newV,oldV){
					if(newV){
						this.getUserInfo();
						this.getIntegralList();
					}
				},
				deep:true
			}
		},
		onLoad() {
			if (this.isLogin) {
				this.getUserInfo();
				this.getIntegralList();
			} else {
				toLogin();
			}
		},
		/**
		   * 页面上拉触底事件的处理函数
		   */
		  onReachBottom: function () {
		    this.getIntegralList();
		  },
		methods: {
			getUserInfo: function() {
				let that = this;
				postIntegralUser().then(function(res) {
					that.$set(that,'integral',res.data);
				});
			},

			/**
			 * 获取积分明细
			 */
			getIntegralList: function() {
				let that = this;
				if (that.loading) return;
				if (that.loadend) return;
				that.loading = true;
				that.loadTitle = '';
				getIntegralList({
					page: that.page,
					limit: that.limit,
					status: that.current,
				}).then(function(res) {
					let list = res.data.list,
						loadend = list.length < that.limit;
					that.integralList = that.$util.SplitArray(list, that.integralList);
					that.$set(that,'integralList',that.integralList);
					that.page = that.page + 1;
					that.loading = false;
					that.loadend = loadend;
					that.loadTitle = loadend ? '我也是有底线的~' : "加载更多";
				}, function(res) {
					this.loading = false;
					that.loadTitle = '加载更多';
				});
			},
			nav: function(current) {
				if (this.loading) return;
				this.current = current;
				this.loadend = false;
				this.loadTitle = ''
				this.integralList = []
				this.page = 1
				this.getIntegralList()
			}
		}
	}
</script>

<style scoped lang="scss">
	.integral-details .header {
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		width: 100%;
		height: 576rpx;
		font-size: 72rpx;
		color: #fff;
		padding: 31rpx 0 45rpx 0;
		box-sizing: border-box;
		font-family: 'Guildford Pro';
		@include main_bg_color(theme);
	}
	.tab{
		margin-top: 50rpx;
		
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.tab-itme{
		width: 157rpx;
		border-radius: 60rpx;
		height: 60rpx;
		background: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		color: #999FAC;
	}
	.tab-itme-on{
		color: #E93323;
		font-weight: bold;
	}
	.integral-num{
		width: 690rpx;
		height: 149rpx;
		background: rgba(255,255,255,0.3);
		border-radius: 20rpx 20rpx 0px 0px;
		border: 2rpx solid rgba(255,255,255,0.3);
		margin: 0 auto;
		margin-top: 44rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.integral-num-item{
		display: flex;
		flex-direction: column;
		width: 108rpx;
		align-items: center;
		justify-content: center;
		
	}
	.integral-num-item-text1{
		font-size: 34rpx;
		color: #FFFFFF;
		
		text-shadow: 0px 2rpx 4rpx rgba(56,80,169,0.5);
	}
	.integral-num-item-text2{
		font-size: 26rpx;
		color: #FFFFFF;
		margin-top: 16rpx;
		text-shadow: 0px 2rpx 4rpx rgba(56,80,169,0.5);
	}
	.integral-sum1{
		font-weight: bold;
		font-size: 60rpx;
		color: #FFFFFF;
		text-shadow: 0px 2rpx 4rpx rgba(11,22,59,0.8);
		margin: 152rpx 0 0 57rpx;
	}
	.integral-sum2{
		font-size: 26rpx;
		color: #FFFFFF;
		margin: 13rpx 0 0 54rpx;
	}
	.integral-details .header .currentScore {
		font-size: 26rpx;
		color: rgba(255, 255, 255, 0.8);
		text-align: center;
		margin-bottom: 11rpx;
	}
	
	.integral-details .header .scoreNum{
		font-family: "Guildford Pro";
	}
	
	.integral-details .header .line {
		width: 60rpx;
		height: 3rpx;
		background-color: #fff;
		margin: 20rpx auto 0 auto;
	}

	.integral-details .header .nav .item {
		width: 33.33%;
		text-align: center;
	}

	.integral-details .header .nav .item .num {
		color: #fff;
		font-size: 40rpx;
		margin-bottom: 5rpx;
		font-family: 'Guildford Pro';
	}
	.wrapper{
		margin-top: -94rpx;
		padding: 0 30rpx;
		background: #F2F3F6;
		border-radius: 32rpx 32rpx 0px 0px;
	}
	.integral-details .wrapper .nav {
		width: 690rpx;
		height: 149rpx;
		background: #FFFFFF;
		border-radius: 0px 0px 20rpx 20rpx ;
	}

	.integral-details .wrapper .nav .item {
		display: flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		font-weight: bold;
		font-size: 30rpx;
		color: #535675;
	}
	.integral-details .wrapper .nav .item .iconfont2 {
		font-size: 28rpx;
		margin-right: 10rpx;
	}

	.integral-details .wrapper .list {
		padding: 24rpx 0;
	}

	.integral-details .wrapper .list .tip {
		font-size: 25rpx;
		width: 690rpx;
		height: 60rpx;
		border-radius: 50rpx;
		background-color: #fff5e2;
		border: 1rpx solid #ffeac1;
		color: #c8a86b;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin-bottom: 24rpx;
	}

	.integral-details .wrapper .list .tip .iconfont2 {
		font-size: 20rpx;
		margin-right: 10rpx;
	}

	.integral-details .wrapper .list .item {
		height: 124rpx;
		border-bottom: 1rpx solid #eee;
		font-size: 24rpx;
		color: #999;
	}

	.integral-details .wrapper .list .item .state {
		font-size: 28rpx;
		color: #282828;
		margin-bottom: 8rpx;
	}

	.integral-details .wrapper .list .item .num {
		font-size: 36rpx;
		font-family: 'Guildford Pro';
	}

	.integral-details .wrapper .list2 {
		background-color: #fff;
		padding: 24rpx 0;
	}

	.integral-details .wrapper .list2 .item {
		background-image: linear-gradient(to right, #fff7e7 0%, #fffdf9 100%);
		width: 690rpx;
		height: 180rpx;
		position: relative;
		border-radius: 10rpx;
		margin: 0 auto 20rpx auto;
		padding: 0 25rpx 0 180rpx;
		box-sizing: border-box;
	}

	.integral-details .wrapper .list2 .item .pictrue {
		width: 90rpx;
		height: 150rpx;
		position: absolute;
		bottom: 0;
		left: 45rpx;
	}

	.integral-details .wrapper .list2 .item .pictrue image {
		width: 100%;
		height: 100%;
	}

	.integral-details .wrapper .list2 .item .name {
		width: 285rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #c8a86b;
	}

	.integral-details .wrapper .list2 .item .earn {
		font-size: 26rpx;
		color: #c8a86b;
		border: 2rpx solid #c8a86b;
		text-align: center;
		line-height: 52rpx;
		height: 52rpx;
		width: 160rpx;
		border-radius: 50rpx;
	}
	
	.font_color{
		@include price_color(theme);
	}
	.item1-page{
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		.item1-text1{
			flex-shrink: 0;
			font-size: 26rpx;
			color: #333;
		}
		.item1-text2{
			font-size: 26rpx;
			color: #666;
			max-width: 300rpx;
			display: block;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
		.item1-text3{
			flex: 1;
			width: 100%;
			height: 26rpx;
			background: #ff9f97;
			position: relative;
			border-radius: 20rpx;
		}
		.item1-text5{
			color: #fff;
			font-size: 20rpx;
			padding: 0 10rpx;
		}
		.item1-text4{
			flex: 1;
			height: 26rpx;
			display: flex;
			justify-content: end;
			border-radius: 20rpx;
			background: -webkit-linear-gradient(0deg, #FF7931 0%, #F11B09 100%);
			position: absolute;
			left: 0%;
			top: 0%;
			z-index: 2;
		}
	}
	.item1-price{
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 26rpx;
		.item1-price-name{
			font-size: 28rpx;
			font-weight: bold;
			color: #333333;
			text-overflow: ellipsis;
			white-space: nowrap;
			overflow: hidden;
			max-width: 300rpx;
		}
		.item1-price-num{
			font-size: 28rpx;
			color: #EA3F30;
		}
	}
	.item1 {
		padding: 40rpx 20rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		position: relative;
	}
	.item1-body {
		display: flex;
		position: relative;
		align-items: center;
		z-index: 2;
	}
	.item1-image2 {
		width: 100%;
		position: absolute;
		left: 0%;
		top: 0%;
		z-index: 1;
	}
	.item1-image{
		width: 208rpx;
		height: 274rpx;
		border-radius: 20rpx;
		margin-right: 24rpx;
		flex-shrink: 0;
	}
	.status3{
		position: absolute;
		top: 0rpx;
		left: 0rpx;
		z-index: 9;
		background: #F09D3A;
		border-radius: 2rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 3rpx 5rpx;
	}
	.status2{
		position: absolute;
		top: 0rpx;
		left: 0rpx;
		z-index: 9;
		background: #000000;
		opacity: 0.6;
		border-radius: 2rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 3rpx 5rpx;
	}
	.status1{
		position: absolute;
		top: 0rpx;
		left: 0rpx;
		z-index: 9;
		background: #45DA7C;
		border-radius: 2rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 3rpx 5rpx;
	}
</style>
